package com.erp.wallet.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.erp.wallet.domain.bo.ErpSellerStoreAccountLogBo;
import com.erp.wallet.domain.vo.ErpSellerStoreAccountLogVo;
import com.erp.wallet.service.IErpSellerStoreAccountLogService;
import com.ruoyi.common.core.annotation.RepeatSubmit;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.web.oldController.BaseController;
import com.ruoyi.common.core.web.oldPage.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * 手工账日志记录
 *
 * @author erp
 * @date 2023-05-31
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/seller/sellerStoreAccountLog")
public class ErpSellerStoreAccountLogController extends BaseController {

    private final IErpSellerStoreAccountLogService iErpSellerStoreAccountLogService;

    /**
     * 查询手工账日志记录列表
     */
    @SaCheckPermission("seller:sellerStoreAccountLog:list")
    @GetMapping("/list")
    public TableDataInfo<ErpSellerStoreAccountLogVo> list(ErpSellerStoreAccountLogBo bo, PageQuery pageQuery) {
        return iErpSellerStoreAccountLogService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出手工账日志记录列表
     */
    @SaCheckPermission("seller:sellerStoreAccountLog:export")
    @Log(title = "手工账日志记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ErpSellerStoreAccountLogBo bo, HttpServletResponse response) {
        List<ErpSellerStoreAccountLogVo> list = iErpSellerStoreAccountLogService.queryList(bo);
//        ExcelUtil.exportExcel(list, "手工账日志记录", ErpSellerStoreAccountLogVo.class, response);
        ExcelUtil<ErpSellerStoreAccountLogVo> excelUtil = new ExcelUtil<>(ErpSellerStoreAccountLogVo.class);
        excelUtil.exportExcel(response,list,"手工账日志记录");
    }

    /**
     * 获取手工账日志记录详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("seller:sellerStoreAccountLog:query")
    @GetMapping("/{id}")
    public R<ErpSellerStoreAccountLogVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iErpSellerStoreAccountLogService.queryById(id));
    }

    /**
     * 新增手工账日志记录
     */
    @SaCheckPermission("seller:sellerStoreAccountLog:add")
    @Log(title = "手工账日志记录", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ErpSellerStoreAccountLogBo bo) {
        return toAjax(iErpSellerStoreAccountLogService.insertByBo(bo));
    }



    /**
     * 修改手工账日志记录
     */
    @SaCheckPermission("seller:sellerStoreAccountLog:edit")
    @Log(title = "手工账日志记录", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ErpSellerStoreAccountLogBo bo) {
        return toAjax(iErpSellerStoreAccountLogService.updateByBo(bo));
    }

    /**
     * 删除手工账日志记录
     *
     * @param ids 主键串
     */
    @SaCheckPermission("seller:sellerStoreAccountLog:remove")
    @Log(title = "手工账日志记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iErpSellerStoreAccountLogService.deleteWithValidByIds(Arrays.asList(ids), true));
    }


}
